﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TjZheng.Controls
{
    public class MySqlQueryCondition : QueryCondition, IQueryCondition
    {

        public string EqualConditionWithParameters(string QueryField, string ParameterName, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            switch (QueryDataType)
            {
                case QueryDataType.String:
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}=?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Int:
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}=?{1}", QueryField, ParameterName);
                    break;
            }
            return objCondition;
        }

        public string NotEqualConditionWithParameters(string QueryField, string ParameterName, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            switch (QueryDataType)
            {
                case QueryDataType.String:
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}<>?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Int:
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}<>?{1}", QueryField, ParameterName);
                    break;
            }
            return objCondition;
        }

        public string GreaterThanConditionWithParameters(string QueryField, string ParameterName, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0}=?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}>?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Int:
                    objCondition = string.Format("{0}>?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}<>?{1}", QueryField, ParameterName);
                    break;

            }
            return objCondition;
        }

        public string LessThanConditionWithParameters(string QueryField, string ParameterName, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0}=?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}<?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Int:
                    objCondition = string.Format("{0}<?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}<>?{1}", QueryField, ParameterName);
                    break;
            }
            return objCondition;
        }

        public string GreaterEqualConditionWithParameters(string QueryField, string ParameterName, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0}=?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}>=?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Int:
                    objCondition = string.Format("{0}>=?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}<>?{1}", QueryField, ParameterName);
                    break;
            }
            return objCondition;
        }

        public string LessEqualConditionWithParameters(string QueryField, string ParameterName, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0}=?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}<=?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Int:
                    objCondition = string.Format("{0}<=?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}<>?{1}", QueryField, ParameterName);
                    break;
            }
            return objCondition;
        }

        public string ContainConditionWithParameters(string QueryField, string ParameterName, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0} like ?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Int:
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}=?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}=?{1}", QueryField, ParameterName);
                    break;
            }
            return objCondition;
        }

        public string StartWithConditionWithParameters(string QueryField, string ParameterName, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0} like ?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Int:
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}=?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}=?{1}", QueryField, ParameterName);
                    break;
            }
            return objCondition;
        }

        public string EndWithConditionWithParameters(string QueryField, string ParameterName, QueryDataType QueryDataType)
        {
            string objCondition = string.Empty;
            switch (QueryDataType)
            {
                case QueryDataType.String:
                    objCondition = string.Format("{0} like ?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.Int:
                case QueryDataType.Boolean:
                    objCondition = string.Format("{0}=?{1}", QueryField, ParameterName);
                    break;
                case QueryDataType.DateTime:
                    objCondition = string.Format("{0}=?{1}", QueryField, ParameterName);
                    break;
            }
            return objCondition;
        }
    }
}
